finp$="picture.png"
'- original qbasic version - 0112141818
'- sdlbasic version - 0405111338
'- halftone picture converter (bmp 4/8/24bit) 

xed=256:yed=192
setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls

while 0=0
  setcaption("dummy")
  shell("vgrabbj -d /dev/video0 -F 4 -f _tmpr1.jpg")
  setcaption("del")
  shell("rm _tmpr1.jpg")
  setcaption("webcam")
  shell("vgrabbj -d /dev/video0 -F 4 -f _tmpr1.jpg")
  setcaption("imagemagick")

'  shell("convert _tmpr1.jpg -resize 256x192\\! _tmpr2.jpg")

  shell("convert _tmpr1.jpg -resize 256x192\\! -level 0%,200% _tmpr2.jpg")

  setcaption("del")
  shell("rm _tmpr1.jpg")
  setcaption("load")
  loadimage("_tmpr2.jpg",1):pasteicon(0,0,1)
  setcaption("del")
  shell("rm _tmpr2.jpg")
  setcaption("conv")

' xed=0:yed=0:open finp$ for input as #1:for i=1 to 16:n=readbyte(1):next:for i=1 to 2:n=readbyte(1):next
' xed=readbyte(1)*256:xed=xed+readbyte(1):for i=1 to 2:n=readbyte(1):next:yed=readbyte(1)*256:yed=yed+readbyte(1)
' close #1
' setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls:

'- opens the image
'loadimage(finp$,1):pasteicon(0,0,1)

dim clust[8,8] '-,o4b[2]
'-- define cluster
' a$="00,12,03,15,08,04,11,07,02,14,01,13,10,06,09,05"
a$="00,06,08,14,02,12,04,10,08,14,00,06,04,10,02,12"
for y2=0 to 3:for x2=0 to 3:lc=(y2*4)+x2
  clust[x2,y2]=val(mid$(a$,(lc*3)+1,2)):next:next
dim cor[16]
cor[0]=0x000000:cor[1]=0x0000FF:cor[2]=0xFF0000:cor[3]=0xFF00FF
cor[4]=0x00FF00:cor[5]=0x00FFFF:cor[6]=0xFFFF00:cor[7]=0xFFFFFF
for y=0 to yed-1
  for x=0 to xed-1
    ind=point(x,y)
    b=ind mod 256:ind=int(ind/256)
    g=ind mod 256:ind=int(ind/256)
    r=ind mod 256

    b=b*2:r=r*2 '- sdl bug fix?

    patgf=(((clust[x mod 4,y mod 4]+1)*255)/16)


    rpat=0
    if r>patgf then:
    rpat=1
    end if

    gpat=0
    if g>patgf then:
    gpat=1
    end if

    bpat=0
    if b>patgf then:
    bpat=1
    end if

    o4b=(bpat+(rpat*2)+(gpat*4)) mod 8
    ink(cor[o4b]):dot(x,y)
    next:next 
'- saves the image
' fout$=finp$+".bmp"
' grab (1,0,0,xed,yed):saveimage(fout$,1)
' shell ("convert "+finp$+".bmp "+finp$+".png")
' shell ("rm "+finp$+".bmp")

waitkey
wend



